require( '$d/css/common.less' );
require( './style.less' );
define( [
	'jquery',
	'require',
	'header',
	'indusCategory',
	'message'
], function( $, require ) {
	var fieldCode = require( 'indusCategory' ),
		ShowTitleMessage = require( 'message' ),
		showTime = ShowTitleMessage.showTime;
	//行业选项start
	var fjid = '';
	for ( var key in fieldCode ) {
		if ( key.length == 4 ) {
			fjid = key;
			if ( key == '0215' ) {
				var str = '<li class="' + key + '"><span class="field-title-choice">' + fieldCode[ key ] + '</span></li>';
			} else {
				var str = '<li class="' + key + '"><div class="industry_cate"><span class="field-title">' + fieldCode[ key ] + '</span></div><div class="industry_list clearfix"></div></li>';
			}
			$( '.fenlei_more>ul' ).append( str );
		}
		if ( key.length == 6 ) {
			var str = '<span _value="' + key + '" class="field-title-choice">' + fieldCode[ key ] + '</span>';
			$( '.' + fjid + ' .industry_list' ).append( str );
		}
	}
	$( '#diag_search .button' ).click( function( e ) {
		e.stopPropagation();
		$( '#diag_search .fenlei_more' ).slideDown();
	} );
	$( '.fenlei_more' ).on( 'click', '.industry_list span', function( e ) {
		e.stopPropagation();
		var _val = $( this ).text();
		var _property = $( this ).attr( '_value' )
		var _title = $( this ).parent( '.industry_list' ).siblings( '.industry_cate' ).find( 'span' ).text();
		$( this ).parents( '.fenlei_more' ).siblings( '.button' ).html( '<span class="' + _property + '">' + _title + '-' + _val + '</span>' );
		$( this ).parents( '.fenlei_more' ).slideUp();
	} );
	$( '.diagnose_banner' ).click( function() {
		$( '#diag_search .fenlei_more' ).slideUp();
	} );
	$( '.fenlei_more' ).mouseleave( function() {
		$( this ).slideUp();
	} );
	//行业选项end
	//banner波浪start
	var wave = document.getElementById( 'wave' );
	var wave_ctx = wave.getContext( '2d' );
	var wave_color = [ "rgba(255,255,255,0.06)", "rgba(255,255,255,0.1)", "rgba(255,255,255,0.14)" ];
	var step = 0;
	var requestAnimFrame = ( function() {
		return window.requestAnimationFrame ||
			window.webkitRequestAnimationFrame ||
			window.mozRequestAnimationFrame ||
			function( callback ) {
				window.setTimeout( callback, 1000 / 60 );
			};
	} )();

	function loop() {
		wave_ctx.clearRect( 0, 0, wave.width, wave.height );
		step++;
		//画3个不同颜色的矩形
		for ( var j = wave_color.length - 1; j >= 0; j-- ) {
			wave_ctx.fillStyle = wave_color[ j ];
			//每个矩形的角度都不同，每个之间相差45度
			var angle = ( step + j * 45 ) * Math.PI / 180;
			var deltaHeight = Math.sin( angle ) * 50;
			var deltaHeightRight = Math.cos( angle ) * 50;
			wave_ctx.beginPath();
			wave_ctx.moveTo( 0, wave.height / 2 + deltaHeight );
			wave_ctx.bezierCurveTo( wave.width / 2, wave.height / 2 + deltaHeight - 50, wave.width / 2, wave.height / 2 + deltaHeightRight - 50, wave.width, wave.height / 2 + deltaHeightRight );
			wave_ctx.lineTo( wave.width, wave.height );
			wave_ctx.lineTo( 0, wave.height );
			wave_ctx.lineTo( 0, wave.height / 2 + deltaHeight );
			wave_ctx.closePath();
			wave_ctx.fill();
		}
		requestAnimFrame( loop );
	}
	loop();
	//banner波浪end
	$( '.diag_immediately input' ).click( function() {
		var _keywords = $( '#diag_search input[type=text]' ).val(),
			_industry = $( '#diag_search .button span' ).text(),
			_value = $( '#diag_search .button span' ).prop( 'class' );
		if ( _keywords == '' ) {
			ShowTitleMessage.showWarning( '请输入标题内容！', showTime );
			return;
		}
		if ( $( '#diag_search .button' ).text() == '适合的行业' ) {
			ShowTitleMessage.showWarning( '请选择行业！', showTime );
			return;
		}
		window.location.href = '/TitleDiagnose/result?keywords=' + _keywords + '&industry=' + _industry + '&value=' + _value;
	} );
} );